package com.xjgzinfo.usdp.config;

import io.minio.MinioClient;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

@Configuration
@ConfigurationProperties(
        prefix = "minio"
)
public class MinioConfiguration implements InitializingBean {
    private String host = "http://127.0.0.1:9000";
    private String url = "http://127.0.0.1:9000";
    private String accessKey;
    private String secretKey;
    private String bucket = "img";

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.hasText(accessKey, "Minio Host为空");
        Assert.hasText(accessKey, "Minio accessKey为空");
        Assert.hasText(secretKey, "Minio secretKey为空");
    }

    @Bean
    MinioClient createMinioClient() throws Exception {
        return new MinioClient(this.host, this.accessKey, this.secretKey);
    }

    public String getBucket() {
        return bucket;
    }

    public void setBucket(String bucket) {
        this.bucket = bucket;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

}
